package ru.ifmo.ipimenov.ewf_svn.standalone.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import ru.ifmo.ipimenov.ewf_svn.standalone.model.db.Document;
import ru.ifmo.ipimenov.ewf_svn.standalone.model.list.Model;
import ru.ifmo.ipimenov.ewf_svn.standalone.view.gui.StateForm;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


/**
 * @author: Ilya Pimenov
 * Scartel Starlab company
 */
public class StateAction implements ActionListener {
    /**
     * Logger for all purposes
     */
    private static Log log = LogFactory.getLog(LoginAction.class);

    private JList list;

    public StateAction(JList list) {
        this.list = list;
    }

    public void actionPerformed(ActionEvent e) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }

    private void createAndShowGUI() {
        JFrame.setDefaultLookAndFeelDecorated(true);

        Model m = (Model) list.getModel();
        Document d = m.getItem(list.getSelectedIndex()).getD();

        JFrame frame = new StateForm(d, list);
//        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        frame.pack();
        frame.setVisible(true);
    }
}